local yanchi = fk.CreateSkill{
  name = "rfenghou_3d13j__yanchi",
}

yanchi:addEffect(fk.TurnStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    local cards = table.filter(player:getCardIds("h"), function (id)
      return Fk:getCardById(id).color == Card.Black or Fk:getCardById(id).type == Card.TypeBasic
    end)
    return player:hasSkill(yanchi.name) and target.hp > player.hp and player:canPindian(target) and #cards > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = table.filter(player:getCardIds("h"), function (id)
      return Fk:getCardById(id).color == Card.Black or Fk:getCardById(id).type == Card.TypeBasic
    end)
    local card = room:askToCards(player, {
      min_num = 1,
      max_num = 1,
      skill_name = yanchi.name,
      pattern = tostring(Exppattern{ id = cards }),
      prompt = "#rfenghou_3d13j__yanchi-pindian:" .. target.id
    })
    if #card > 0 then
      event:setCostData(self, { cards = card, tos = { target } })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local pindian = player:pindian({target}, yanchi.name, Fk:getCardById(event:getCostData(self).cards[1]))
    if target.dead or player:isProhibited(target, Fk:cloneCard("slash")) then return end
    if pindian.results[target].winner == player or
      (pindian.fromCard.color == Card.Black and pindian.fromCard.type == Card.TypeBasic) then
      if room:askToSkillInvoke(player, {
        skill_name = yanchi.name,
        prompt = "#rfenghou_3d13j__yanchi-slash::"..target.id .. ":" .. pindian.fromCard:toLogString(),
      }) then
        local card = Fk:cloneCard("slash")
        card.skillName = yanchi.name
        card:addSubcard(pindian.fromCard)
        local use = {
          from = player,
          tos = {target},
          card = card,
          extraUse = true,
        }
        room:useCard(use)
      end
    end
  end
})

Fk:loadTranslationTable{
  ["rfenghou_3d13j__yanchi"] = "砚斥",
  [":rfenghou_3d13j__yanchi"] = "体力值大于你的角色的回合开始时，你可以用一张黑色牌或基本牌与其拼点，若之为黑色基本牌或你赢，你可以将你的拼点牌当【杀】对其使用。",

  ["#rfenghou_3d13j__yanchi-slash"] = "砚斥：你可以将 %arg 当【杀】对 %dest 使用",
  ["#rfenghou_3d13j__yanchi-pindian"] = "砚斥：你可以用一张黑色牌或基本牌与 %src 拼点，若之为黑色基本牌或你赢，你可以将之当【杀】对其使用",
}

return yanchi
